package com.casic.ops.runner.pipeline.manager;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Properties;

/**
 * 自定义的session管理器。后面可删了
 * @author cww
 * @date 2022/6/17
 */
@Slf4j
@Service
public class MySessionManager {



    public synchronized Session get() {


        Session session = null;
        try {
            JSch jsch = new JSch();
            session = jsch.getSession("root", "120.48.5.101", 22);
            // 设置密码
            session.setPassword("#*CWW123");
            Properties config = new Properties();
            config.put("StrictHostKeyChecking", "no");
            // 为Session对象设置properties
            session.setConfig(config);
            // 设置timeout时间
            session.setTimeout(50000);
            // 通过Session建立链接
            session.connect();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return session;
        }
    }

}
